home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SAT 2.3b4 / SAT Think Lib ƒ / SAT.p < prev    next >
Text File  |  1995-05-01  |  12KB  |  253 lines

  1. unit SAT;
  2.  
  3. interface
  4.  
  5.     type
  6.         SATPort = record
  7.                 port: GrafPtr;        {GrafPtr/WindowPtr, use for SetPort, ShowWindow…}
  8.                 device: GDHandle;    {Internal}
  9.                 rows: Ptr;            {Internal}
  10.                 bounds: Rect;            {Internal}
  11.                 baseAddr: Ptr;        {Internal}
  12.                 rowBytes: Integer;    {Internal}
  13.             end;
  14.         SATPortPtr = ^SATPort;
  15.  
  16.         FacePtr = ^Face;
  17.         Face = record
  18.                 colorData: Ptr;
  19.                 resNum: integer;
  20.                 iconMask: BitMap;
  21.                 rowBytes: integer;
  22.                 next: FacePtr;
  23.                 maskRgn: RgnHandle;
  24.                 rows, maskRows: Ptr;
  25.                 redrawProc: ProcPtr;    {Called on depth changes, not needed if loaded from a cicn}
  26.             end;
  27.  
  28.         SpritePtr = ^Sprite;
  29.         Sprite = record
  30. { Variables that you should change as appropriate }
  31.                 kind: Integer; { Used for identification. >0: friend. <0 foe }
  32.                 position: Point;
  33.                 hotRect, hotRect2: Rect; { Tells how large the sprite is; hotRect is centered around origo }
  34.                                     {hotRect is set by you. hotRect2 is offset to the current position.}
  35.                 face: FacePtr;            { Pointer to the Face (appearance) to be used. }
  36.                 task: ProcPtr;            { Callback-routine, called once per frame. If task=nil, the sprite is removed. }
  37.                 hitTask: ProcPtr;        { Callback in collisions. }
  38.                 destructTask: ProcPtr;    { Called when a sprite is disposed. (Usually nil.) }
  39.                 clip: RgnHandle;            {Clip region to be used when this sprite is drawn.}
  40. { SAT variables that you shouldn't change: }
  41.                 oldpos: Point;                {Used by RunSAT2}
  42.                 next, prev: SpritePtr;    {You may change them in your own sorting routine, but be careful if you do.}
  43.                 r, oldr: Rect;                {Rectangle telling where to draw. Avoid messing with it.}
  44.                 oldFace: FacePtr;            {Used by RunSAT2}
  45.                 dirty: Boolean;            {Used by RunSAT2}
  46. {Variables for internal use by the sprites. Use as you please. Edit as necessary - this is merely a default}
  47. {set, enough space for most cases - but if you change the size of the record, call SetSpriteSize immediately}
  48. {after initializing (before any sprites are created)!}
  49.                 layer: integer; {For layer-sorting. When not used for that, use freely.}
  50.                 speed: Point; { Can be used for speed, but not necessarily. }
  51.                 mode: integer; { Usually used for different modes and/or to determine what image to show next. }
  52.                 appPtr: Ptr; {Pointer for use by the application - i.e. pointer to extra data}
  53.                 appLong: Longint; {Longint for free use by the application.}
  54.             end;
  55.  
  56. {Type for SATs pattern utilities.}
  57.     type
  58.         SATPattern = record
  59.                 patternType: integer; {1 = Pattern, PatHandle, 2 = PixPat, PixPatHandle}
  60.                 thePat: PixPatHandle; {or PatHandle}
  61.             end; {record}
  62.         SATPatPtr = ^SATPattern;
  63.         SATPatHandle = ^SATPatPtr;
  64.  
  65. {Update list. Used internally}
  66.         UpdatePtr = ^UpdateRec;
  67.         UpdateRec = record
  68.                 updateRect: Rect;
  69.                 next: UpdatePtr;
  70.             end;
  71.  
  72. {The globals record. Some fields are important for you. These are marked with *}
  73.         SATglobalsRec = record
  74.                 wind: SATPort;                                {*The window that SAT draws in. You get the WindowPtr as gSAT.wind.port}
  75.                 offSizeH, offSizeV: integer;                    {*Offscreen size, used to limit sprite positions}
  76.                 offScreen: SATPort;                            {*Offscreen image }
  77.                 backScreen: SATPort;                        {*Background image }
  78.  
  79.                 ox, oy: longint;                                {Internal}
  80.                 pict, bwpict: integer;                        {PICT id's}
  81.                 fitThePICTs: boolean;                        {Resize PICTs to fit?}
  82.                 sorting: integer;                                {Chosen sorting}
  83.                 collision: integer;                            {Chosen collision handling}
  84.                 searchWidth: integer;                        {Chosen search width}
  85.                 screen: PixMapHandle;                        {Internal}
  86.                 bounds: Rect;                                    {Internal}
  87.                 initDepth: Integer;                            {*Depth at last icon initialization}
  88.                 synchHook: ProcPtr;                            {Synch procedure}
  89.                 sRoot: SpritePtr;                                {Sprite list root}
  90.                 updateRoot: UpdatePtr;                        {Update list root}
  91.                 anyMonsters: Boolean;                        {*False when no sprites with kind < -1 are active }
  92.  
  93.                 ditherOff: CGrafPtr;                            {Internal}
  94.                 ditherOffGD: GDHandle;                        {Internal}
  95.                 iconPort: SATPort;                            {Internal}
  96.                 iconPort2: SATPort;                            {Internal}
  97.                 bwIconPort: GrafPtr;                         {Internal}
  98. {Environment-independent globals:}
  99.                 faceRoot: FacePtr;                            {Root of face list}
  100.                 colorFlag: Boolean;                            {True if color QuickDraw is available.}
  101.                 mmuMode: SignedByte;                        {Addressing mode}
  102. {Blitters! You should not change these fields yourself. (Possibly for installing a blitter in your program code.)}
  103.                 rectBlit1, maskBlit1: ProcPtr;                {Supplied - this is either RBlt/MBlt 0 or 1}
  104.                 rectBlit2, maskBlit2: ProcPtr;                {Will probably never be used}
  105.                 rectBlit4, maskBlit4: ProcPtr;                {Supplied}
  106.                 rectBlit8, maskBlit8: ProcPtr;                {Supplied}
  107.                 rectBlit16, maskBlit16: ProcPtr;            {Not supplied}
  108.                 rectBlit32, maskBlit32: ProcPtr;            {Not supplied}
  109.                 curRectBlit, curMaskBlit: ProcPtr;            {Currently selected fast blitter}
  110.                 screenLocalDrawingArea: Rect;
  111.             end;
  112.  
  113. {Configuration types: VPositionSort and KindCollision are defaults.}
  114.     const
  115. {Sorting options}
  116.         kVPositionSort = 0;
  117.         kLayerSort = 1;
  118.         kNoSort = 2;
  119. {Collision detection options}
  120.         kKindCollision = 0;
  121.         kForwardCollision = 1;
  122.         kBackwardCollision = 2;
  123.         kNoCollision = 3;
  124.         kForwardOneCollision = 4;
  125.  
  126.     var
  127. {$J+}
  128.         gSAT: SATglobalsRec;                {Most globals in a record. See above.}
  129.         gSATSoundErrorProc: ProcPtr;        {Pointer to procedure to call on sound error.}
  130. {$J-}
  131.  
  132. {Initializing and customizing}
  133.     procedure SATConfigure (PICTfit: boolean; newSorting, newCollision, searchWidth: integer);
  134.     procedure SATInit (pictID, bwpictID, Xsize, Ysize: integer);
  135.     procedure SATCustomInit (pictID, bwpictID: integer; SATdrawingArea: Rect; {}
  136.                                     preloadedWind: WindowPtr; chosenScreen: GDHandle; useMenuBar, {}
  137.                                     centerDrawingArea, fillScreen, dither4bit, beSmart: Boolean);
  138. {Maintainance, background manipulation etc.}
  139.     function SATDepthChangeTest: Boolean;
  140.     procedure SATDrawPICTs (pictID, bwpictID: integer);
  141.     procedure SATRedraw;
  142. {Drawing}
  143.     procedure SATPlotFace (theFace: FacePtr; theGrafPtr: SATPortPtr; where: Point; Fast: boolean);
  144.     procedure SATPlotFaceToScreen (theFace: FacePtr; where: Point; Fast: boolean);
  145. {SATCopybits is now only done with a CopyBits - so it's really obsolete.}
  146.     procedure SATCopyBits (src, dest: SATPortPtr; {}
  147.                                     srcRect, destRect: Rect; fast: Boolean);
  148.     procedure SATCopyBitsToScreen (src: SATPortPtr; srcRect, destRect: Rect; fast: Boolean);
  149.     procedure SATBackChanged (r: Rect); {Tell SAT about changes in backScreen}
  150. {SetPort replacements}
  151.     procedure SATGetPort (var port: SATPort);
  152.     procedure SATSetPort (port: SATPort);
  153.     procedure SATSetPortOffScreen; {Use before using QuickDraw on offScreen}
  154.     procedure SATSetPortBackScreen; {Use before using QuickDraw on backScreen}
  155.     procedure SATSetPortScreen; {Use to set port to gSAT.wind}
  156. {Basic sprite handling}
  157.     function SATGetFace (resNum: Integer): FacePtr;
  158.     procedure SATDisposeFace (theFace: FacePtr);
  159.     function SATNewSprite (kind, hpos, vpos: Integer; setup: ProcPtr): SpritePtr;
  160.     function SATNewSpriteAfter (afterthis: SpritePtr; kind, hpos, vpos: Integer; setup: ProcPtr): SpritePtr;
  161.     procedure SATKillSprite (who: Spriteptr);
  162. {Animating}
  163.     procedure SATRun (fast: Boolean); {The heart of the whole package!}
  164.     procedure SATRun2 (fast: Boolean); {Alternate routine for allowing resting sprites}
  165. {Special functions for advanced programmers}
  166.     procedure SATInstallSynch (theSynchProc: ProcPtr);
  167.     procedure SATInstallEmergency (theEmergencyProc: ProcPtr);
  168.     procedure SATSetSpriteRecSize (theSize: longint);
  169.     procedure SATSkip;
  170.     procedure SATKill; {Dispose of offscreen buffers to allow re-init}
  171.     procedure SATWindMoved;
  172. {Offscreen - use only if you need an *extra* offscreen buffer. These calls are likely to change in the future!}
  173.     procedure SATMakeOffscreen (var portP: SATPort; rectP: Rect); {Make offscreen buffer in current screen depth and CLUT.}
  174.     procedure SATDisposeOffScreen (var portP: SATPort); {Get rid of offscreen}
  175.     function CreateOffScreen (bounds: Rect; depth: Integer; colors: CTabHandle; var retPort: CGrafPtr; var retGDevice: GDHandle): OSErr; {From Principia Offscreen - color only}
  176.     procedure DisposeOffScreen (doomedPort: CGrafPtr; doomedGDevice: GDHandle);{From Principia Offscreen - color only}
  177. {Face manipulation (for advanced programmers)}
  178.     procedure SATSetPortMask (theFace: FacePtr);
  179.     procedure SATSetPortFace (theFace: FacePtr);
  180.     procedure SATSetPortFace2 (theFace: FacePtr);
  181.     function SATNewFace (faceBounds: Rect): FacePtr;
  182.     procedure SATChangedFace (theFace: FacePtr);
  183.  
  184. {New procedures, EXPERIMENTAL, intended for making a C++ interface}
  185.     function SATGetFacePP (resNum: integer; fStorage: Ptr): FacePtr;
  186.     function SATNewSpritePP (afterthis: SpritePtr; sStorage: Ptr; theKind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;
  187.     procedure SATCopySprite (destSprite: SpritePtr; srcSprite: SpritePtr);
  188.     function SATNewFacePP (faceBounds: Rect; fStorage: Ptr): FacePtr;
  189.     procedure SATCopyFace (destFace: FacePtr; srcFace: FacePtr);
  190.     procedure SATDisposeFacePP (theFace: FacePtr);
  191.  
  192. {Cicn utilities}
  193.     function SATGetCicn (cicnId: integer): CIconHandle;
  194.     procedure SATPlotCicn (theCicn: CIconHandle; dest: GrafPtr; destGD: GDHandle; r: Rect); {Borde jag lägga till device?}
  195.     procedure SATDisposeCicn (theCicn: CIconHandle);
  196.  
  197. {Utilities}
  198.     procedure SATSetStrings (ok, yes, no, quit, memerr, noscreen, nopict, nowind: Str255);
  199.     function SATTrapAvailable (theTrap: Integer): Boolean;
  200.     procedure SATDrawInt (i: Integer);
  201.     procedure SATDrawLong (l: Longint);
  202.     function SATRand (n: Integer): Integer;
  203.     function SATRand10: Integer;
  204.     function SATRand100: Integer;
  205.     procedure SATReportStr (str: str255);
  206.     function SATQuestionStr (str: str255): Boolean;
  207.     function SATFakeAlert (s1, s2, s3, s4: Str255; nButtons, defButton, cancelButton: Integer;{}
  208.                                     t1, t2, t3: Str255): integer;
  209.     procedure CheckNoMem (p: Ptr); {If the Ptr is nil, out of memory emergency exit}
  210.     procedure SATSetMouse (where: Point);
  211.     procedure SATInitToolbox;
  212.     procedure SATGetVersion (var versionString: Str255);
  213. {Pattern utilities}
  214.     procedure SATPenPat (SATpat: SATPatHandle);
  215.     procedure SATBackPat (SATpat: SATPatHandle);
  216.     function SATGetPat (patID: Integer): SATPatHandle;
  217.     procedure SATDisposePat (SATpat: SATPatHandle);
  218. {Menu bar utilities}
  219.     procedure SATShowMBar (wind: WindowPtr);
  220.     procedure SATHideMBar (wind: WindowPtr);
  221. {PICT utilities}
  222.     procedure SATGetandDrawPICTRes (id: Integer);
  223.     procedure SATGetandDrawPICTResInRect (id: Integer; frame: Rect);
  224.     procedure SATGetandCenterPICTResInRect (id: Integer; frame: Rect);
  225. {Sound}
  226.     procedure SATSoundInit; {Called from SATInit}
  227.     procedure SATSoundPlay (theSound: Handle; priority: Integer; canWait: Boolean);
  228.     procedure SATSoundEvents; {Call this once in a while when not calling SATRun often}
  229.     procedure SATSoundShutup; {Silence, dispose of sound channel}
  230.     procedure SATSoundOn;
  231.     procedure SATSoundOff;
  232.     function SATSoundDone: Boolean; {Any sound going on ?}
  233.     function SATGetSound (sndId: integer): Handle;        { To load a sound and get a handle for SATSoundPlay }
  234.     function SATGetNamedSound (name: Str255): Handle; { Same but using resource names }
  235.     procedure SATDisposeSound (theSnd: handle);
  236. {Multi-channel sound routines}
  237.     function SATSoundInitChannels (num: integer): Integer;
  238.     function SATSoundDoneChannel (chanNum: integer): Boolean;
  239.     procedure SATSoundPlayChannel (theSound: Handle; chanNum: Integer);
  240.     procedure SATSoundReserveChannel (chanNum: integer; reserve: Boolean);
  241.     procedure SATSoundShutupChannel (chanNum: Integer);
  242.     procedure SATPreloadChannels;
  243. {Experimental, likely to be renamed/removed/changed:}
  244.     procedure SATSoundPlay2 (theSound: Handle; priority: Integer; canWait, skipIfSame: Boolean);
  245.     procedure SATSoundPlayEasy (theSound: Handle; canWait: Boolean);
  246. {More multi-channel:}
  247.     function SATGetNumChannels: Integer;
  248.     function SATGetChannel (chanNum: Integer): Ptr;
  249. {Customization}
  250.     procedure SATSetSoundInitParams (params: Longint);
  251.  
  252. implementation
  253. end.